package com.oa.config;
import cn.org.rapid_framework.freemarker.directive.BlockDirective;
import cn.org.rapid_framework.freemarker.directive.ExtendsDirective;
import cn.org.rapid_framework.freemarker.directive.OverrideDirective;
import com.jagregory.shiro.freemarker.ShiroTags;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.servlet.MultipartConfigElement;

@Configuration
public class FreeMakerConfig {

    @Autowired
    private freemarker.template.Configuration configuration;

    private static final Logger logger= LoggerFactory.getLogger(FreeMakerConfig.class);

    @PostConstruct
    public void setSharedVariable(){
        logger.info("配置freemarker");
        configuration.setSharedVariable("block", new BlockDirective());
        configuration.setSharedVariable("override", new OverrideDirective());
        configuration.setSharedVariable("extends", new ExtendsDirective());
        configuration.setSharedVariable("shiro",new ShiroTags());
        configuration.setTagSyntax(0);
    }

    @Bean
    public MultipartConfigElement configElement(){
        MultipartConfigFactory factory= new MultipartConfigFactory();
        factory.setLocation("c:/apps/pttms/tmp");
        return factory.createMultipartConfig();
    }
}
